from starlette.endpoints import HTTPEndpoint
from starlette.responses import JSONResponse
from model.ModPendingProRep import PendingProRep, pendingProRepSchema
from database import Session, engine
import datetime


def get_pending_pro_rep(session, bureauid: str, flag: str):
    # 待处理问题统计表
    connection = engine.raw_connection()
    try:
        cursor = connection.cursor()
        cursor.callproc("statics_pending_pro_rep")
        cursor.close()
        connection.commit()
        pending_pro = session.query(PendingProRep).filter(PendingProRep.bureauid == bureauid).filter(
            PendingProRep.flag == flag).all()
        return JSONResponse(pendingProRepSchema.dump(pending_pro, many=True).data)
    finally:
        connection.close()
